﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class User_ChoosePaper : System.Web.UI.Page
{
    Datacon dataconn = new Datacon();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            string sqlPaperid = string.Format("select PAPERID from [USER] where ID='" + Session["ID"] + "'");
            DataTable dt = dataconn.GetDataSetSql(sqlPaperid).Tables[0];
            string PAPERID = dt.Rows[0]["PAPERID"].ToString();
            dataconn.ecDropDownList(ddlQueName, "select * from TaoTi where PaperID in("+ PAPERID + ") and PaperState='" + 1 + "'", "PaperName", "PaperID");

        }

    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        SqlConnection con = dataconn.getcon();
        con.Open();
        string sqlstr1 = "select count(*) from Score where UserID ='" + Session["ID"] + "' and PaperID='" + ddlQueName.SelectedValue + "'";
        SqlCommand mycom = new SqlCommand(sqlstr1, con);
        int intcount = Convert.ToInt32(mycom.ExecuteScalar());
        Session["PaperID"] = ddlQueName.SelectedValue;
        Session["PaperName"] = ddlQueName.SelectedItem;
        if (this.ddlQueName.Text == "")
        {
            Response.Write("<script lanuage=javascript>alert('您还没有选择考试套题，请重新选择！');location='javascript:history.go(-1)'</script>");
        }
        else if (intcount > 0)
        {
            Response.Write("<script lanuage=javascript>alert('此套题已经答过！');location='javascript:history.go(-1)'</script>");
        }
        else
        {
            Response.Redirect("wait.aspx");
        }
    }



    protected void ddlQueName_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}